<?php
/**
 * 包含书籍排行榜的控制器类
 */
class Rank extends Controller
{
	
   /**
    * 类的构造函数
    */
   function Rank()
	{
		parent::Controller();
        $this->load->model('book_model');
        $this->load->model('user_model');
        $this->load->model('post_model');
        $this->load->library('session');
        $this->load->library('mypagination');
        //$this->output->enable_profiler(TRUE);
        //$this->output->cache(1);   //cache the page for n minutes
	}


    /**
     * 最热门二手书排行控制器
     */
    function hotbook(){
        //配置分页函数
        if(isset($_GET['curpage']))
           $offset=$_GET['curpage'];
        else
           $offset=0;
        $config['page_query_string'] = TRUE;
        if(!isset($_GET['totalrows'])){
              $result=$this->book_model->get_hottest_book(1,$offset,15);
              $config['total_rows'] =$result[0]->number;
        }
        else{
           $config['total_rows'] =$_GET['totalrows'];
        }
        $link="rank/hotbook?go=yes&totalrows={$config['total_rows']}";
        $config['base_url'] = site_url($link);
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $config['per_page']=15;
        $this->mypagination->initialize($config);
        $data['bookarray'] = $this->book_model->get_hottest_book(0,$offset,15);
        $data['title'] = "热门二手书排行榜";
	    $data['activetab']="rank";
        $data['user_status']=$this->user_model->get_user_status(); //获取用户登录状态
        $data['hottest_book']=$this->book_model->get_hottest_book(0,0,10); //total=0,offset=0,per_page=10
        list($schoolsetstatus,$school)=$this->user_model->get_schoolinitial();
        $data['hottest_shop']=$this->user_model->get_shops(0,$school,-1,0,10); //total=0,offset=0,per_page=10
        $this->load->view('rank/hotbook', $data);
    }


    /**
     * 最热门求购二手书控制器
     */
    function wanted(){
        //配置分页函数
        if(isset($_GET['curpage']))
           $offset=$_GET['curpage'];
        else
           $offset=0;
        $config['page_query_string'] = TRUE;
        list($schoolsetstatus,$school)=$this->user_model->get_schoolinitial();

         if(!isset($_GET['totalrows'])){
              $result=$this->post_model->getlatest_wantedpost(1,$school,$offset,20);
              $config['total_rows'] =$result[0]->number;
        }
        else
           $config['total_rows'] =$_GET['totalrows'];
         $link="rank/wanted?go=yes&totalrows={$config['total_rows']}";
        $config['base_url'] = site_url($link);
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $config['per_page']=20;
        $this->mypagination->initialize($config);
        $data['recent_wantedpost'] = $this->post_model->getlatest_wantedpost(0,$school,$offset,20);
        $data['title'] = "最新求购排行榜";
	    $data['activetab']="rank";
        $data['user_status']=$this->user_model->get_user_status(); //获取用户登录状态
        $data['hottest_book']=$this->book_model->get_hottest_book(0,0,10); //total=0,offset=0,per_page=10
        $data['hottest_shop']=$this->user_model->get_shops(0,$school,-1,0,10); //total=0,offset=0,per_page=10
        $this->load->view('rank/wanted', $data);
    }

    /*
     * 最热门的出售二手书排行榜控制器
     */
    function sale(){
        //配置分页函数
        if(isset($_GET['curpage']))
           $offset=$_GET['curpage'];
        else
           $offset=0;
        $config['page_query_string'] = TRUE;
        list($schoolsetstatus,$school)=$this->user_model->get_schoolinitial();
       if(!isset($_GET['totalrows'])){
              $result=$this->post_model->getlatest_salepost(1,$school,$offset,20);
              $config['total_rows'] =$result[0]->number;
        }
        else
           $config['total_rows'] =$_GET['totalrows'];
         $link="rank/sale?go=yes&totalrows={$config['total_rows']}";
        $config['base_url'] = site_url($link);
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $config['per_page']=20;
        $this->mypagination->initialize($config);
        $data['recent_salepost'] = $this->post_model->getlatest_salepost(0,$school,$offset,20);
        $data['title'] = "最新出售排行榜";
	    $data['activetab']="rank";
        $data['user_status']=$this->user_model->get_user_status(); //获取用户登录状态
        $data['hottest_book']=$this->book_model->get_hottest_book(0,0,10); //total=0,offset=0,per_page=10
        $data['hottest_shop']=$this->user_model->get_shops(0,$school,-1,0,10); //total=0,offset=0,per_page=10
        $this->load->view('rank/sale', $data);
    }

    /**
     * 最热门店铺控制器
     */
    function hotshop(){

        //配置分页函数
        if(isset($_GET['curpage']))
           $offset=$_GET['curpage'];
        else
           $offset=0;
        $config['page_query_string'] = TRUE;
        list($schoolsetstatus,$school)=$this->user_model->get_schoolinitial();
        if(!isset($_GET['totalrows'])){
              $result=$this->user_model->get_shops(1,$school,-1,$offset,20);  //campusid=-1,代表所有校区
              $config['total_rows'] =$result[0]->number;
        }
        else
           $config['total_rows'] =$_GET['totalrows'];
        $link="rank/hotshop?go=yes&totalrows={$config['total_rows']}";
        $config['base_url'] = site_url($link);
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
        $config['per_page']=20;
        $this->mypagination->initialize($config);
        $shops= $this->user_model->get_shops(0,$school,-1,$offset,20);
        foreach($shops as $shop){
           $shop->campus=$this->user_model->get_campus($shop->campus_id);
        }
        $data['all_hottest_shop']=$shops;
        $data['title'] = "最热书店排行榜";
	    $data['activetab']="rank";
        $data['user_status']=$this->user_model->get_user_status(); //获取用户登录状态
        $data['hottest_book']=$this->book_model->get_hottest_book(0,0,10); //total=0,offset=0,per_page=10
        $data['hottest_shop']=$this->user_model->get_shops(0,$school,-1,0,4); //total=0,offset=0,per_page=10
        $this->load->view('rank/hotshop', $data);
    }

}
?>
